function formatTime(date) {
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()

  var hour = date.getHours()
  var minute = date.getMinutes()
  var second = date.getSeconds();


  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

function transLocalTime(t) {
  return new Date(t * 1000);
}

function formatNumber(n) {
  n = n.toString()
  return n[1] ? n : '0' + n
}

module.exports = {
  formatTime: formatTime,
  transLocalTime: transLocalTime
}

//
String.prototype.isEmpty = function () {
  if (this.replace(/(^\s*)|(\s*$)/g, '').length <= 0) {//null
    return true;
  }
  else {// not null
    return false;
  }
};
String.prototype.notEmpty = function () {
  return !this.isEmpty();
};
String.prototype.isEmail = function () {
  if (this.isEmpty() || (!/^([\w]+)(.[\w]+)*@([\w-]+\.){1,5}([A-Za-z]){2,4}$/.test(this))) {//格式不正确
    return false;
  } else {// 格式正确
    return true;
  }
};
String.prototype.isPhoneNumber = function () {
  if (this.isEmpty() || (!/^1([3-9][0-9]{9})$/.test(this))) {//格式不正确
    return false;
  } else {// 格式正确
    return true;
  }
};
String.prototype.isNumber = function () {
  if (this.isEmpty() || (!/^[0-9]+$/.test(this))) {
    return false;
  } else {
    return true;
  }
};
String.prototype.trim = function () {
  return this.replace(/^\s*/img, "").replace(/\s*$/img, "");
};
function json2Form(json) {
  var str = [];
  for (var p in json) {
    str.push(encodeURIComponent(p) + "=" + encodeURIComponent(json[p]));
  }
  return str.join("&");
}